//
//  WoaOpenApi.h
//  woa_two
//
//  Created by xie bin on 11-11-23.
//  Copyright (c) 2011年 SNDA. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>
//#define WOA_TEST YES

typedef enum {
	eNoOpt = 100,
	eInit,			//start oa
    eAutoLogin,		//auto login
	eLogin,       //login
    eLoginWithKey, //loginWithKey
    eValidate,
    eCheckUserName,
    eRegister,
    eCallBack,
    eExLogin,
    eExAutoLogin,
    eSMSUserDefine,
}EOPT;

typedef NSInteger eOptType;

typedef enum {
	eLoginDone = 200,	//login complete
	eNeedKey,         //need Ekey authentic
	eNeedA8Key,       //need A8Key authentic
	eNeedSafeCard,    //need safe card authentic
    eNeedCheckCode,   //need check code authentic
}ELOGINTYPE;
typedef NSInteger woaLoginType;

typedef NSInteger woaErrorCode;
typedef enum {
    woaErrorCodeSuccess = 0,     //成功
    woaErrorCodeUnknown =  -10801001, //未知错误
    woaErrorCodeNetError = -10801000,//检查通讯网络情况 网络有问题
    woaErrorCodeServerFail = -10801002, //服务器处理失败 
    woaErrorCodeServerError = -10801003,//服务异常，请检查网络或稍候再试
    woaErrorCodeWaitCheck = -10801011,//等待安全校检
    woaErrorCodeIsLogining = -10801021,//通行证登陆中
    woaErrorCodeNoSim = -10801004,//无SIM卡
    woaErrorCodeNeedEkey = -10801010,//需要密宝验证
    woaErrorCodeNeedA8Ekey = -10801020, //需要A8密宝验证
    woaErrorCodeNeedECard = -10801030,//需要安全卡验证
    woaErrorCodeNeedCheckCode = -10801040,//需要图片验证码验证
    woaErrorCodeNoAutoLoginToken = -10801005,//没有自动登录标识
    woaErrorCodeSendSmsFail = -10801006,//发送短信失败
    woaErrorCodeNeedInputMobile = -10801007,//需要输入手机号码
    woaErrorCodeNeedInputValidateCode = -10801101,//需要输入验证码
    woaErrorCodeNeedPtLogin = -10801103,//请先使用通行证登录
    woaErrorCodeSDKNotInit = -10801099,//SDK没有初始化
    woaErrorCodeServierInvalid = -10801008,//其他服务正在运行,请稍候重试
    woaErrorCodeNeedInputUserId = -10801104, //需要输入通行证
    woaErrorCodesSimOperatorNotCn = -10801015,//SIM卡不是国内的
    woaErrorCodeMobileCanNotSendSms = -10801016,//无法上行短信
    
    woaErrorCodePtAccountError = -10890001, //通行证和密码不匹配
    woaErrorCodeKeyInvalid = -10890002, //无效的密宝
    woaErrorCodeSafeCardInvalid = -10890003, //无效的安全卡密码
    woaErrorCodeCheckCodeInvalid = -10890009,//无效的验证码
    woaErrorCodeLoginTimeOut = -10890004,//登录超时
    woaErrorCodeAutoLoginInvalid = -10890005,//自动登录已失效，请重新登录
    woaErrorCodeCancelSendSms = -10890006,//短信发送取消
    woaErrorCodePtAccountExistError = -10890007,//账号已经存在
    woaErrorCodeGetGuidError = -10890008 //guid获取失败
}WOAERRORCODE;
typedef NSInteger woaEventStatusCode;
//错误描述资源
#define STATUS_DES_DICT [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"成功",@"未知错误",@"检查通讯网络情况,网络有问题",@"服务器处理失败",@"服务异常，请检查网络或稍候再试",@"等待安全校检",@"通行证登陆中 ",@"无SIM卡"\
,@"需要密宝验证",@"需要A8密宝验证",@"需要安全卡验证",@"没有自动登录标识",@"发送短信失败",@"需要输入手机号码",@"需要输入验证码",@"请先使用通行证登录"\
,@"SDK没有初始化",@"其他服务正在运行,请稍候重试",@"需要输入通行证",@"SIM卡不是国内的",@"无法上行短信",@"通行证和密码不匹配",@"无效的密宝",@"无效的安全卡密码"\
,@"登录超时",@"自动登录已失效，请重新登录",@"短信发送取消",@"用户名已经存在",@"guid获取失败",@"无效的验证码",nil]\
forKeys:[NSArray arrayWithObjects:[NSNumber numberWithInt:woaErrorCodeSuccess]\
,[NSNumber numberWithInt:woaErrorCodeUnknown]\
,[NSNumber numberWithInt:woaErrorCodeNetError]\
,[NSNumber numberWithInt:woaErrorCodeServerFail]\
,[NSNumber numberWithInt:woaErrorCodeServerError]\
,[NSNumber numberWithInt:woaErrorCodeWaitCheck]\
,[NSNumber numberWithInt:woaErrorCodeIsLogining]\
,[NSNumber numberWithInt:woaErrorCodeNoSim]\
,[NSNumber numberWithInt:woaErrorCodeNeedEkey]\
,[NSNumber numberWithInt:woaErrorCodeNeedA8Ekey]\
,[NSNumber numberWithInt:woaErrorCodeNeedECard]\
,[NSNumber numberWithInt:woaErrorCodeNoAutoLoginToken]\
,[NSNumber numberWithInt:woaErrorCodeSendSmsFail]\
,[NSNumber numberWithInt:woaErrorCodeNeedInputMobile]\
,[NSNumber numberWithInt:woaErrorCodeNeedInputValidateCode]\
,[NSNumber numberWithInt:woaErrorCodeNeedPtLogin]\
,[NSNumber numberWithInt:woaErrorCodeSDKNotInit]\
,[NSNumber numberWithInt:woaErrorCodeServierInvalid]\
,[NSNumber numberWithInt:woaErrorCodeNeedInputUserId]\
,[NSNumber numberWithInt:woaErrorCodesSimOperatorNotCn]\
,[NSNumber numberWithInt:woaErrorCodeMobileCanNotSendSms]\
,[NSNumber numberWithInt:woaErrorCodePtAccountError]\
,[NSNumber numberWithInt:woaErrorCodeKeyInvalid]\
,[NSNumber numberWithInt:woaErrorCodeSafeCardInvalid]\
,[NSNumber numberWithInt:woaErrorCodeLoginTimeOut]\
,[NSNumber numberWithInt:woaErrorCodeAutoLoginInvalid]\
,[NSNumber numberWithInt:woaErrorCodeCancelSendSms]\
,[NSNumber numberWithInt:woaErrorCodePtAccountExistError]\
,[NSNumber numberWithInt:woaErrorCodeGetGuidError]\
,[NSNumber numberWithInt:woaErrorCodeCheckCodeInvalid]\
,nil]]


#define keyLoginType  @"loginType"
#define keyErrorCode @"errorCode"
#define keyErrorMsg @"errorMsg"
#define keyNeedValidate @"needValidate"

#define keyRandomNum @"randomNum"
#define keyECardPos @"ECardPos"
#define keyChallenge @"Challenge"
#define keyCheckCode @"CheckCodeUrl"

#define keyAuthenState @"authenState"

#define keySsn     @"ssn"
#define keySmsText @"smsText"


@protocol woaDelegate;
/**
 仅允许单例，请使用shareWoaOpenAPI
 */
@interface WoaOpenApi : NSObject {
    BOOL _isInit;
}

+(WoaOpenApi *)shareWoaOpenAPI;
@property(nonatomic)BOOL isInit;
@property (nonatomic, readonly, getter = getSndaId) NSString *sndaId;
//@property(nonatomic,retain)NSString *retain;
/**
    初始化设置
    返回NO时已经初始化
 */
-(BOOL)woaInit;

/**
	发送短信验证并登录
	@param viewCtrl 实现了MFMessageComposeViewControllerDelegate的UIViewController
    @returns YES调用成功， NO当前设置可能不支持发送短信SMS
 */
- (BOOL)mobileSendSMSLogin:(UIViewController *)viewCtrl;

/**
 发送短信验证并登录，不发送，只返回相应短信参数
 @returns YES调用成功， NO不能成功返回
 */
- (BOOL)mobileSendSMSLoginWithoutUI;

/**
 接收(下行)短信验证码并登录带界面
 @param phoneNumber 接收短信的电话号码
 */
//- (void)mobileReceiveSMSLoginIn:(UIViewController *)viewCtrl;

/**
	接收(下行)短信验证码并登录
	@param phoneNumber 接收短信的电话号码
 */
- (void)mobileReceiveSMSLogin:(NSString *)phoneNumber;

/**
	调用mobileReceiveSMSLogin后会收到短信验证码
	@param code 传入短信验证码
	@returns 如果是在下行短信验证流程则直接返回YES，否则返回NO
 */
- (BOOL)checkVerificationCode:(NSString *)code;

/**
 使用曾经登录成功过的sessionid自动登录
 @returns 当前允许自动登录返回YES  不允许自动登录返回NO
 */
- (BOOL)autoLogin;

/**
 手机号登陆一次一密成功后的回调接口
 @param resCode 
 @param dic
      type  = 0  手机号登陆成功  = 1 
      token 
 */
-(void)callBack:(int)resCode result:(NSDictionary *)dic;

/**
 一次一密，验证sessionId是否有效
 @returns 当前允许自动登录返回YES  不允许自动登录返回NO
 */
//- (BOOL)validate:(NSString *)sessionId;

/**
	使用边锋通行证+密码登录
	@param pt 边锋通行证
	@param pwd 密码
 */
- (void)loginByPT:(NSString *)pt password:(NSString *)pwd;

/**
 使用pt登录后输入验证码
 @param key 验证码
 @param type 验证码类型
 */
- (void)loginWithKey:(NSString*)key type:(ELOGINTYPE)type;

/**
 检测用户名是否存在
 @param userName 用户名
 */
- (void)userNameExists:(NSString *)userName;

/**
 个性化账号注册
 @param userName 用户名
 @param pwd 密码
 */
- (void)userNameRegister:(NSString *)userName password:(NSString *)password;

/**
 体验账号注册登陆
 */
- (int)canExLogin;

/**
 体验账号注册登陆
 */
- (void)exLogin;

/**
 体验账号自动登陆
 */
- (void)exAutoLogin;

/**
 本机账号自动登陆
 */
- (BOOL)mobileAutoLogin;


/**
 是否开启地理位置服务
 @param enabled 是否开启
 默认为app开启位置服务后开启，关闭则不开启，
 */
-(void)setLocationServiceEnable:(BOOL)enabled;

/**
 获取支持的国家列表
 */
- (NSString *)getCountListStr;

/**
 获取认证凭证
 */
- (NSString *)getSessionId;

/**
 获取登录状态信息
 */
- (NSString *)getResultMsg;

/**
 获取特服号
 */
- (NSString *)getSSN;

/**
 获取登录状态
 */
- (NSInteger)getResultCode;
/**
 获取UUID
 */
- (NSString *)getUUID;
/*
 *清除掉登陆信息
 */
-(void)loginOff;

//取消后不再响应回调
- (void)cancel;

/**
 应用的appId，默认值是零，所有功能不可用
 */
@property (nonatomic, readwrite) NSUInteger appId;

/**
 登录的区id默认值是零
 */
@property (nonatomic, readwrite) NSUInteger areaId;


@property (nonatomic, readwrite) NSUInteger productId;

@property (nonatomic, readwrite) NSUInteger channelId;

@property (nonatomic, retain) NSString *ptAccount;

@property (nonatomic, assign) id <woaDelegate> delegate;

/**
 标识当前是否为测试环境
 */
@property (readonly) BOOL isTestSet;

@end

@protocol woaDelegate <NSObject>
@optional
/**
	发送短信前，让用户有机会处理发送短信界面外观
	@param smsViewController 短信发送ViewController
 */
- (void)mobileSendSMSLoginBefore:(MFMessageComposeViewController *)smsViewController;

/**
	发送短信登录结果
	@param code 错误码
	@param msg 错误信息
 */
- (void)mobileSendSMSLoginResult:(NSInteger)code msg:(NSString *)msg;

/**
	下行短信验证结果
	@param code 错误码
	@param msg 错误信息
 */
- (void)mobileReceiveSMSLoginResult:(NSInteger)code msg:(NSString *)msg;

/**
	验证码验证结果
	@param code 错误码
	@param msg 错误信息
 */
- (void)checkVerificationCodeResult :(NSInteger)code msg:(NSString *)msg;

/**
 操作成功(现在主要用作登录接口)
 */
- (void)onSuccess:(eOptType)optType result:(NSDictionary*)paraDic;
/**
 操作失败(现在主要用作登录接口)
 */
- (void)onFail:(eOptType)optType result:(NSDictionary*)paraDic;

@end
